﻿/*
* 创建人:            @Model.Author
* 创建时间:          @Model.CreateTime
* 邮箱：             @Model.EmailAddress
* 文件功能描述：      @Model.FileRemark
* 
* 修改人： 
* 时间：
* 修改说明：
*/
@using SJNScaffolding.Models.CollectiveType
@using SJNScaffolding.WPF.Extend
@model SJNScaffolding.Models.TemplateModels.ViewFileModel
using System.Threading.Tasks;
using System.Web.Mvc;
using @(Model.ProjectName).Domain.Plat.@(Model.TableName)s;
using @(Model.ProjectName).Domain.Plat.@(Model.TableName)s.Dto;
using @(Model.ProjectName).Web.Controllers;
using HbAssess.Domain.Common.Files;
namespace @(Model.ProjectName).Web.Areas.Plat.Controllers
{
    public class @(Model.TableName)Controller : @(Model.ProjectName)ControllerBase
    {
        #region 构造函数
        private readonly I@(Model.TableName)AppService _@(Model.TableNameCamel)AppService;
@if (Model.WebUploadList.Count > 0){@RazorHelper.RawHtml("      private readonly IAbpFileAppService _fileAppService;\r\n");}
        public @(Model.TableName)Controller(I@(Model.TableName)AppService @(Model.TableNameCamel)AppService 
@if(Model.WebUploadList.Count > 0){@RazorHelper.RawHtml("                               ,IAbpFileAppService fileAppService\r\n")}
                                )
        {
            this._@(Model.TableNameCamel)AppService = @(Model.TableNameCamel)AppService;  
@if(Model.WebUploadList.Count > 0){@RazorHelper.RawHtml("           this._fileAppService = fileAppService;\r\n")}
        }
        #endregion

        // GET: Plat/@(Model.TableName)

        #region 视图
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult CreateOrUpdateModal()
        {
            return View();
        }

        #endregion

        #region 数据
        public async Task<@("ActionResult")> GetInfoForEdit(int id)
        {
            var output = await _@(Model.TableNameCamel)AppService.GetInfoForEdit(id);
            @if (Model.WebUploadList.Count>0)
            {
                string webuploadParams = "";
                foreach (WebUploadColunm r in Model.WebUploadList)
                {
                    webuploadParams+=",_fileAppService.GetFileOutput(output."+r.WebuploadId+")";
                }
@RazorHelper.RawHtml("              var "+Model.TableNameCamel + "ViewModel=new " +Model.TableName + "ViewModel(output"+webuploadParams+");\r\n");
@RazorHelper.RawHtml("          return Json("+Model.TableNameCamel+"ViewModel"+ ");\r\n");
            }
            else{
@RazorHelper.RawHtml("          return Json(output);\r\n");
            }
        }

        public ActionResult GetGridByCondition(@(Model.TableName)SearchDto input)
        {
            var gridData = _@(Model.TableNameCamel)AppService.GetGridByCondition(input);
            return Json(gridData);
        }
        #endregion

    }
}